package com.nf.health.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.RecommendList;
import com.nf.health.app.utils.ImageLoaderUtils;
import com.nf.health.app.utils.LogUtil;

import java.util.List;

public class MySportAdapter extends BaseAdapter {
	private Context context;
	private List<RecommendList> listHealthy;
	private OnMyClickListener listener;

	public MySportAdapter(Context context,List<RecommendList> mySportList) {
		this.context = context;
		this.listHealthy = mySportList;
		LogUtil.i(mySportList.toString());
	}

	@Override
	public int getCount() {
		if(listHealthy != null){
			return listHealthy.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return listHealthy.get(position);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_healthy_plan, position);
		ImageView sport_icon = holder.getView(R.id.sport_icon);
		ImageLoaderUtils.getinstance(context).getImage(
				sport_icon,
				listHealthy.get(position).getHimg(),
				R.drawable.new_default_nf_icon);
		holder.setText(R.id.sport_name,listHealthy.get(position).getSchemename());
		holder.setText(R.id.sport_suit_type, listHealthy.get(position).getDesc());
		TextView hold_finish = holder.getView(R.id.hold_finish);
		if (TextUtils.isEmpty(listHealthy.get(position).getSign())) {
			hold_finish.setText("");
			hold_finish.setBackgroundResource(R.drawable.home_add_hplan);
		} else {
			if (listHealthy.get(position).getSign().equals("n")) {
				hold_finish.setBackgroundResource(R.drawable.new_hold_finish);
			} else if (listHealthy.get(position).getSign().equals("y")) {
				hold_finish.setText(null);
				hold_finish.setBackgroundResource(R.drawable.home_state_two);
			}
		}
		hold_finish.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View view) {
				listener.onClick(position, MySportAdapter.class.getSimpleName());
			}
		});
		return holder.getConvertView();
	}
	
	public void setOnMyClickListener(OnMyClickListener listener){
		this.listener = listener;
	}
}
